<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>给类添加方法</title>
</head>

<body>
  <script>
    class Star {
      constructor(uname, age) {
        this.uname = uname
        this.age = age
      }
      // 注意：方法与方法之间不加逗号; 方法不加function关键字
      song() {
        console.log('唱歌');
      }
      dance(i) {
        console.log(this.uname + i);
      }
    }

    // 实例化对象
    var ldh = new Star('刘德华', 18)
    ldh.song();  // 唱歌
    ldh.dance('跳芭蕾');  //刘德华跳芭蕾
  </script>
</body>

</html>